package com.yuwubao.hz_International.services.impl;

import com.yuwubao.hz_International.entities.InviteRewardsConfigEntity;
import com.yuwubao.hz_International.entities.repository.InviteRewardsConfigRepository;
import com.yuwubao.hz_International.services.InviteRewardsConfigService;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by yangyu on 2018/1/28.
 */
@Service
public class InviteRewardsConfigServiceImpl implements InviteRewardsConfigService {

    @Autowired
    private InviteRewardsConfigRepository inviteRewardsConfigRepository;

    @Resource
    private JdbcTemplate jdbcTemplate;

    @Override
    public List<InviteRewardsConfigEntity> findAll() {
        return inviteRewardsConfigRepository.findAll();
    }

    @Override
    public InviteRewardsConfigEntity save(InviteRewardsConfigEntity inviteRewardsConfig) {
        return inviteRewardsConfigRepository.save(inviteRewardsConfig);
    }

    @Override
    public InviteRewardsConfigEntity update(InviteRewardsConfigEntity inviteRewardsConfig) {
        InviteRewardsConfigEntity inviteRewardsConfigEntity = inviteRewardsConfigRepository.findOne(inviteRewardsConfig.getId());
        if (inviteRewardsConfig != null) {
            ModelMapper model = new ModelMapper();
            InviteRewardsConfigEntity entity = model.map(inviteRewardsConfig, InviteRewardsConfigEntity.class);
            return inviteRewardsConfigRepository.save(entity);
        }
        return null;
    }
}
